package com.vaadin.thomas.contenttool.ui;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.vaadin.terminal.Sizeable;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.thomas.contenttool.data.Value;
import com.vaadin.thomas.contenttool.data.Version;
import com.vaadin.ui.Embedded;

public class Util {

	public static Embedded getFlag(String locale) {
		Embedded e = new Embedded(null, new ThemeResource("flags/" + locale
				+ ".png"));
		e.setWidth(16, Sizeable.UNITS_PIXELS);
		e.setHeight(11, Sizeable.UNITS_PIXELS);
		e.addStyleName("flag");
		return e;
	}

	public static Embedded getIcon(String icon) {
		Embedded e = new Embedded(null, new ThemeResource("icons/" + icon
				+ ".png"));
		e.setWidth(16, Sizeable.UNITS_PIXELS);
		e.setHeight(16, Sizeable.UNITS_PIXELS);
		e.addStyleName("icon");
		return e;
	}

	public static String parseVersion(Version v) {

		if (v.isPreview()) {
			return MainLayout.ct().get(
					"contenttool.content.oldversions.version-preview");
		} else if (v.isProduction()) {
			return MainLayout.ct().get(
					"contenttool.content.oldversions.version-production");
		}

		return MainLayout.ct().get("contenttool.content.oldversions.version")
				+ " " + v.getVersionNumber();
	}

	public static void filterCTIdentifiers(List<Value> vals,
			boolean showContentToolIdentifiers) {
		if (!showContentToolIdentifiers) {
			Set<Value> toRemove = new HashSet<Value>();
			for (Value v : vals) {
				if (v.getId().startsWith("contenttool")) {
					toRemove.add(v);
				}
			}
			vals.removeAll(toRemove);
		}
	}

}
